/**
 * Copyright (C) 2012 The SkyTvOS Project
 * <p/>
 * Version     Date           Author
 * ─────────────────────────────────────
 * 2014-7-18         luwei
 */

package com.tianci.appstore.ui.search;

import android.content.Context;
import android.view.View;
import android.widget.FrameLayout;

import com.coocaa.x.uipackage.widget.SlideFocusView;
import com.tianci.appstore.R;
import com.tianci.appstore.utils.SkyConstants;

public class SearchInputLayout extends FrameLayout {

    protected ClearFocusListener mClearFocusListener = null;
    public SearchKeyLayout metroKeyLayout;
    protected SlideFocusView.FocusChangedEvent mFocusChangedEvent = null;
    protected SlideFocusView.FocusViewRevision mRevision = null;
    protected int mItemBackId = R.drawable.search_keyboard_selector;

    public SearchInputLayout(Context context) {
        super(context);
    }


    public interface ClearFocusListener {
        public boolean clearFocus(int keyCode);
    }

    public void setClearFocusListener(ClearFocusListener listener) {
        this.mClearFocusListener = listener;
    }

    public void setFocusChangeEvent(SlideFocusView.FocusChangedEvent event) {
        if (event != null) {
            this.mFocusChangedEvent = event;
            this.mItemBackId = R.drawable.game_center_search_btn;
            mRevision = new SlideFocusView.FocusViewRevision(SkyConstants.Div(
                    SearchMainLayout.SEARCH_SHADOW_X), SkyConstants.Div(SearchMainLayout.SEARCH_SHADOW_Y));
        }
    }

    public void setFirstFocus() {
        if (metroKeyLayout != null) {
            metroKeyLayout.setFocusItem(0);
        }
    }

    protected void setFocusChangeEvent(View view) {
        if (mFocusChangedEvent != null) {
            mFocusChangedEvent.registerView(view, mRevision);
        }
    }

    protected void setFocusChangeEvent(View view, OnFocusChangeListener listener) {
        if (mFocusChangedEvent != null) {
            view.setOnFocusChangeListener(null);
            mFocusChangedEvent.registerView(view, mRevision, listener);
        }
    }

}
